<template>
  <div class="container-box">
    <!-- 头部信息 -->
    <!--START 生产简报title -->
    <div class="header">
      <div class="title">{{ $t('overview.title') }}</div>
      <div class="date">{{ date }}</div>
      <div class="shift-selector">
        <div class="activeAF shift-option">
          <el-icon>
            <Star />
          </el-icon>
          <text>AF</text>
        </div>
        <div class="activeMF shift-option" >
          <el-icon>
            <StarFilled />
          </el-icon>
          <text>MF</text>
        </div>
        <!-- <div class="shift-option" :class="{ active: shift === 'today' }" @click="selectDayType('today')">
          <el-icon>
            <Calendar />
          </el-icon>
          <text>{{ $t('overview.today') }}</text>
        </div> -->
      </div>
      <!-- 多语言 -->
      <div class="language-dropdown-wrapper">
        <el-dropdown @command="changeLanguage">
          <span class="language-dropdown-link">
            {{ lang === 'zh-CN' ? '中文' : 'English' }}
            <el-icon class="el-icon--right"><arrow-down /></el-icon>
          </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item command="zh-CN">中文</el-dropdown-item>
              <el-dropdown-item command="en-US">English</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </div>
    <!--END 生产简报 title-->

    <!-- 自定义导航栏 -->
    <div class="overview-nav-bar">
      <div v-for="tab in navTabs" :key="tab.key" class="nav-item" :class="{ active: activeTab === tab.key }"
        @click="selectTab(tab.key)">
        <el-icon>
          <component :is="tab.icon" />
        </el-icon>
        <span>{{ $t('overview.' + tab.key) }}</span>
        <div class="nav-underline" v-if="activeTab === tab.key"></div>
      </div>
    </div>

    <!-- 内容区域 -->
    <div class="content overview-cards">
      <template v-if="activeTab === 'material'">
        <ProcessInfo />
      </template>
      <template v-else-if="activeTab === 'equipment'">
        <Summary />
      </template>
      <template v-else>
        <!-- 当日到货卡片区 -->
        <div class="card-group arrival-group">
          <div class="card-title arrival-title">
            <img src="./img/ov.png" alt="ov" class="arrival-title-img" />
            <span>{{ $t('overview.stockSummary') }}</span>
          </div>
          <div class="arrival-list">
            <div class="arrival-item">
              <img src="./img/AF-in.png" alt="AF-in" class="arrival-img" />
              <div class="arrival-label">{{ $t('overview.afTodayIn') }}</div>
              <div class="af arrival-value ">{{ inventory.dailyInboundAF }} <span class="arrival-unit">{{
                $t('overview.unitPallet') }}</span></div>
            </div>

            <div class="arrival-item">
              <img src="./img/AF-out.png" alt="AF-out" class="arrival-img" />
              <div class="arrival-label">{{ $t('overview.afTodayOut') }}</div>
              <div class="af arrival-value ">{{ inventory.dailyOutboundAF }} <span class="arrival-unit">{{
                $t('overview.unitPallet') }}</span></div>
            </div>
            <div class="arrival-item">
              <img src="./img/3.png" alt="AF" class="arrival-img" />
              <div class="arrival-label">{{ $t('overview.afInventoryTotal') }}</div>
              <div class="af arrival-value ">{{ inventory.totalFinishedProductsInStockAF }} <span
                  class="arrival-unit">{{
                    $t('overview.unitPallet') }}</span></div>
            </div>
            <!-- 分割线 -->
            <div class="arrival-divider-flex">
              <div class="divider-line"></div>
              <img class="divider-img" src="./img/PK.gif" alt="PK" />
              <div class="divider-line"></div>
            </div>
            <div class="arrival-item">
              <img src="./img/MF-in.png" alt="MF-in" class="arrival-img" />
              <div class="arrival-label">{{ $t('overview.mfTodayIn') }}</div>
              <div class="mf arrival-value arrival-value-blue">{{ inventory.dailyInboundMF }} <span
                  class="arrival-unit">{{
                    $t('overview.unitPallet') }}</span></div>
            </div>
            <div class="arrival-item">
              <img src="./img/MF-out.png" alt="MF-out" class="arrival-img" />
              <div class="arrival-label">{{ $t('overview.mfTodayOut') }}</div>
              <div class="mf arrival-value arrival-value-blue">{{ inventory.dailyOutboundMF }} <span
                  class="arrival-unit">{{ $t('overview.unitPallet') }}</span></div>
            </div>
            <div class="arrival-item">
              <img src="./img/2.png" alt="MF" class="arrival-img" />
              <div class="arrival-label">{{ $t('overview.mfInventoryTotal') }}</div>
              <div class="mf arrival-value arrival-value-blue">{{ inventory.totalFinishedProductsInStockMF }} <span
                  class="arrival-unit">{{ $t('overview.unitPallet') }}</span></div>
            </div>
          </div>
        </div>

        <!-- 合并高合格率工序和高人效工序，仅在非手机端 -->
        <template v-if="!isMobile">
          <div class="card-list">
            <div class="card-group">
              <div class="card-title">
                <img src="./img/process.png" alt="process" class="process-title-img" />
                <span>{{ $t('overview.highPassRateProcess') }}</span>
              </div>
              <div class="process-chart-wrapper">
                <div class="env-main">
                  <div class="env-block">
                    <div class="env-label">
                      <!-- <span class="tag af-tag ">AF</span> -->
                      <span class="env-proc">{{findProcessName(processList.AFProcessName) }}</span>
                    </div>
                    <div class="af env-value">{{ processList.AFProcessPercent || $t('overview.noData') }}</div>
                    <!-- <div class="env-range">{{ $t('overview.passRateRange') }}</div> -->
                  </div>
                  <div class="env-block">
                    <div class="env-label">
                      <!-- <span class="tag mf-tag af-tag">MF</span> -->
                      <span class="env-proc">{{findProcessName(processList.MFProcessName) }}</span>
                    </div>
                    <div class="mf env-value">{{ processList.MFProcessPercent || $t('overview.noData') }}</div>
                    <!-- <div class="env-range">{{ $t('overview.passRateRange') }}</div> -->
                  </div>
                </div>
              </div>
            </div>
            <div class="card-group">
              <div class="card-title">
                <img src="./img/User.png" alt="User" class="user-title-img" />
                <span>{{ $t('overview.highEfficiencyProcess') }}</span>
              </div>
              <div class="eff-chart-wrapper">
                <div class="env-main">
                  <div class="env-block1 env-block">
                    <!-- <div class="env-label"><span class=" af-tag">AF</span></div> -->
                    <div class="af env-value" style="margin: 3px 0;">{{ findProcessName(processList.AFEfficiency)||
                      $t('overview.noData') }}</div>
                  </div>
                  <div class="env-block1 env-block">
                    <!-- <div class="env-label"><span class="mf-tag af-tag">MF</span></div> -->
                    <div class="mf env-value" style="margin: 3px 0;">{{ findProcessName(processList.MFEfficiency) ||
                      $t('overview.noData') }}</div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </template>
        <!-- 手机端分开显示 -->
        <template v-else>
          <div class="card-group">
            <div class="card-title">
              <img src="./img/process.png" alt="process" class="process-title-img" />
              <span>{{ $t('overview.highPassRateProcess') }}</span>
            </div>
            <div class="process-chart-wrapper">
              <div class="env-main">
                <div class="env-block">
                  <div class="env-label">
                    <!-- <span class="tag af-tag">AF</span> -->
                    <span class="env-proc">{{findProcessName(processList.AFProcessName) }}</span>
                  </div>
                  <div class="af env-value">{{ processList.AFProcessPercent || $t('overview.noData') }}</div>
                  <!-- <div class="env-range">{{ $t('overview.passRateRange') }}</div> -->
                </div>
                <div class="env-block">
                  <div class="env-label">
                    <!-- <span class="tag mf-tag af-tag">MF</span> -->
                    <span class="env-proc">{{findProcessName(processList.MFProcessName) }}</span>
                  </div>
                  <div class="mf env-value">{{ processList.MFProcessPercent || $t('overview.noData') }}</div>
                  <!-- <div class="env-range">{{ $t('overview.passRateRange') }}</div> -->
                </div>
              </div>
            </div>
          </div>
          <div class="card-group">
            <div class="card-title">
              <img src="./img/User.png" alt="User" class="user-title-img" />
              <span>{{ $t('overview.highEfficiencyProcess') }}</span>
            </div>
            <div class="eff-chart-wrapper">
              <div class="env-main">
                <div class="env-block">
                  <!-- <div class="env-label"><span class="af-tag">AF</span></div> -->
                  <div class="af env-value">{{ findProcessName(processList.AFEfficiency) || $t('overview.noData') }}</div>
                </div>
                <div class="env-block">
                  <!-- <div class="env-label"><span class="mf-tag af-tag">MF</span></div> -->
                  <div class="mf env-value">{{ findProcessName(processList.MFEfficiency) || $t('overview.noData') }}</div>
                </div>
              </div>
            </div>
          </div>
        </template>
        <!-- 缺料预警区块 -->
        <div class="card-group warning-group">
          <div class="card-title">
            <img src="./img/expanded.png" alt="expanded" class="warning-title-img" />
            <span>{{ $t('overview.materialShortageWarning') }}</span>
          </div>
          <div class="bar-chart-2rows-wrapper">
            <div v-for="bar in shortageBars" :key="bar.label" class="bar-row">
              <div :class="bar.label=='AF'?'af':'mf'" class="bar-label" >{{ $t('overview.' + bar.label.toLowerCase()) }}</div>
              <div class="bar-bg" @click="scrollToMaterialDetail">
                <div class="bar-fill" :style="{ width: getBarWidth(bar.value), background: bar.color }"></div>
              </div>
              <div class="bar-value" @click="scrollToMaterialDetail">{{ bar.value }}{{ $t('overview.unitPiece') }}</div>
            </div>
            <!-- <div class="bar-x-axis">
              <span v-for="i in 6" :key="i" class="bar-tick">{{ (i - 1) * tick }}</span>
            </div> -->
          </div>
        </div>
      </template>
    </div>
  </div>
</template>
<script setup>
import { reactive, ref, onMounted, onBeforeUnmount, nextTick } from 'vue';
import { useI18n } from 'vue-i18n';
import { Calendar, Coin, Box, UserFilled, Timer, EditPen, User, Plus, ArrowDown, ArrowRight, Warning, Check, CircleCheck, CircleClose, InfoFilled, User as UserIcon, ShoppingCart, HomeFilled } from '@element-plus/icons-vue';
import * as echarts from 'echarts';
import ProcessInfo from '../ProcessInfo/ProcessInfo.vue';
import Summary from '../Summary/Summary.vue';
import { getDateList, getProcess } from '@/api/index';

const { locale, t } = useI18n();
let lang = ref(localStorage.getItem('lang') || 'zh-CN');
if (!localStorage.getItem('lang')) {
  localStorage.setItem('lang', 'zh-CN');
}

// 计算当前时间减去14小时
const getDate = () => {
  const now = new Date();
  now.setTime(now.getTime() - 14 * 60 * 60 * 1000);
  const year = now.getFullYear();
  const month = String(now.getMonth() + 1).padStart(2, '0');
  const day = String(now.getDate()).padStart(2, '0');
  return `${year}-${month}-${day}`;
};

const keyProcessList = [
  { key: 'JC', 'zh-CN': '挤出', 'en-US': 'Extrusion' },
  { key: 'LVT', 'zh-CN': 'LVT', 'en-US': 'LVT' },
  { key: 'LMHH', 'zh-CN': 'UV淋膜', 'en-US': 'Laminating' },
  { key: 'TH', 'zh-CN': '贴合', 'en-US': 'Gluing' },
  { key: 'JKJ', 'zh-CN': '锯开检', 'en-US': 'Saw cutting' },
  { key: 'PE', 'zh-CN': 'PE', 'en-US': 'PE' },
  { key: 'DR', 'zh-CN': '打包', 'en-US': 'Pack and wrap' }
];

const findProcessName = (key) => {
  const lang = localStorage.getItem('lang') || 'zh-CN';
  const process = keyProcessList.filter(item => item.key === key);
  console.log(process.length >= 1 ? process[0][lang] : key);
  return process.length >= 1 ? process[0][lang] : key;
};

// 获取URL参数中的date
function getUrlDate() {
  // 支持 ?date=xxxx-xx-xx 或 #/xxx?date=xxxx-xx-xx
  const search = window.location.search || '';
  const hash = window.location.hash || '';
  let match = search.match(/[?&]date=([0-9]{4}-[0-9]{2}-[0-9]{2})/);
  if (!match && hash) {
    match = hash.match(/[?&]date=([0-9]{4}-[0-9]{2}-[0-9]{2})/);
  }
  return match ? match[1] : '';
}

const urlDate = getUrlDate();
const date = ref(urlDate || getDate());
// 导航栏配置
const navTabs = [
  { key: 'staff', icon: UserIcon },
  { key: 'material', icon: ShoppingCart },
  { key: 'equipment', icon: HomeFilled }
];
const activeTab = ref('staff');
function selectTab(key) {
  activeTab.value = key;
  selectDataList();
}
// 语言切换功能（示例）
const changeLanguage = (newLang) => {
  lang.value = newLang;
  locale.value = newLang;
  localStorage.setItem('lang', newLang);
};

// 班次选择功能
const selectShift = (shift) => {
  console.log(`Selected shift: ${shift}`);
};
// 汇总数据
const inventory = reactive({
  dailyInboundAF: 0,
  dailyOutboundAF: 0,
  totalFinishedProductsInStockAF: 0,
  dailyInboundMF: 0,
  dailyOutboundMF: 0,
  totalFinishedProductsInStockMF: 0
})

// 缺料预警
const shortageBars = reactive([
  { label: 'AF', value: 0, unit: '个', color: 'linear-gradient(90deg, #aad9f3, #007AFF)' },
  { label: 'MF', value: 0, unit: '个', color: 'linear-gradient(90deg, #a8eff1, #4caf50)' }
]);

// d缺料预警调整物料详情
const scrollToMaterialDetail = () => {
  console.log('scrollToMaterialDetail')
  activeTab.value = 'material'
  document.getElementById('material-detail')?.scrollIntoView({ behavior: 'smooth' });
}

const tick = ref(5)
function getBarWidth(value) {
  const maxValue = tick.value * 5; // 使用tick值作为最大值，乘以5是因为x轴有6个刻度点(0到5*tick)
  // 确保进度条宽度在0-100%之间
  const width = Math.min((value / maxValue) * 100, 100);
  return `${Math.max(width, 0)}%`;
}

const processList = ref({
  AFProcess: '',
  MFProcess: '',
  AFProcessName: '',
  MFProcessName: '',
  AFEfficiency: '',
  MFEfficiency: '',
}); // 工序数据

// 响应式判断是否为手机端
const isMobile = ref(window.innerWidth <= 468);
function handleResize() {
  isMobile.value = window.innerWidth <= 468;
}

onMounted(() => {
  window.addEventListener('resize', handleResize);
  handleResize();
  selectDataList();
});
onBeforeUnmount(() => {
  window.removeEventListener('resize', handleResize);
});

const selectDataList = () => {
  let date = urlDate || getDate();
  // 获取接口数据
  getDateList({ date: date }).then(res => {
    if (res.code === 200) {
      const af = res.result.filter(x => x.tenantId == 8050)[0] || {};
      const mf = res.result.filter(x => x.tenantId == 8080)[0] || {};
      inventory.dailyInboundAF = af.dailyInbound || 0;
      inventory.dailyOutboundAF = af.dailyOutbound || 0;
      inventory.totalFinishedProductsInStockAF = af.totalFinishedProductsInStock || 0;
      inventory.dailyInboundMF = mf.dailyInbound || 0;
      inventory.dailyOutboundMF = mf.dailyOutbound || 0;
      inventory.totalFinishedProductsInStockMF = mf.totalFinishedProductsInStock || 0;
      // 高合格率工序
      if (af.highQualityProcess) {
        const match = af.highQualityProcess.match(/([^(]+)\(([^)]+)\)/);
        processList.value.AFProcessName = match ? match[1] : af.highQualityProcess;
        processList.value.AFProcessPercent = match ? match[2] : '';
      } else {
        processList.value.AFProcessName = '-';
        processList.value.AFProcessPercent = '-';
      }
      if (mf.highQualityProcess) {
        const match = mf.highQualityProcess.match(/([^(]+)\(([^)]+)\)/);
        processList.value.MFProcessName = match ? match[1] : mf.highQualityProcess;
        processList.value.MFProcessPercent = match ? match[2] : '';
      } else {
        processList.value.MFProcessName = '-';
        processList.value.MFProcessPercent = '-';
      }
      // 高人效工序
      processList.value.AFEfficiency = af.highEfficiencyProcess || '-';
      processList.value.MFEfficiency = mf.highEfficiencyProcess || '-';
      // 缺料预警
      shortageBars[0].value = af.materialShortageWarningCount || 0;
      shortageBars[1].value = mf.materialShortageWarningCount || 0;
      // 计算合适的tick值，确保进度条能正确显示
      const maxValue = Math.max(Number(af.materialShortageWarningCount) || 0, Number(mf.materialShortageWarningCount) || 0);
      // 根据最大值动态计算tick值
      if (maxValue === 0) {
        // 如果所有值都为0，设置默认刻度为2，x轴显示0,2,4,6,8,10
        tick.value = 2;
      } else if (maxValue <= 5) {
        // 最大值≤5时，tick=1，x轴显示0,1,2,3,4,5
        tick.value = 1;
      } else if (maxValue <= 10) {
        // 最大值≤10时，tick=2，x轴显示0,2,4,6,8,10
        tick.value = 2;
      } else if (maxValue <= 25) {
        // 最大值≤25时，tick=5，x轴显示0,5,10,15,20,25
        tick.value = 5;
      } else {
        // 最大值>25时，动态计算tick
        tick.value = Math.ceil(maxValue / 5);
      }
    }
  }).catch(err => {
    console.error('getDateList error:', err);
  });

}
</script>

<style scoped lang="scss">
// 公共样式
.af {
  color: #007AFF !important;
}

.mf {
  color: #4caf50 !important;
}

.bar-value:hover {
  background-color: rgba(35, 38, 243, 0.1);
}

.header {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px;
  background-color: #f8f8f8;
  border-bottom: 1px solid #e0e0e0;
  color: white;
  position: relative;
  overflow: visible;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  animation: slide 20s infinite;
  transition: background-image 0s;
  background-image: linear-gradient(rgba(0, 0, 0, 0.23), rgba(0, 0, 0, 0.23)), url("@/views/Overview/img/image.png");
  background-size: 100% 100%;
  z-index: 10;

  .title {
    font-size: 45px;
    text-align: center;
    margin-top: 0;
    font-weight: bold;
    letter-spacing: 3px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    position: relative;
    padding-bottom: 10px;
  }

  .title::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 50px;
    height: 3px;
    background-color: #007AFF;
  }

  .date {
    text-align: center;
    margin-top: 15px;
    margin-bottom: 15px;
    font-size: 18px;
    color: rgba(255, 255, 255, 0.8);
    font-style: italic;
  }

  .shift-selector {
    display: flex;
    justify-content: center;
    gap: 15px;
  }

  .shift-option {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 5px 10px;
    border-radius: 20px;
    background-color: rgba(255, 255, 255, 0.2);
    color: white;
    cursor: pointer;
    transition: background-color 0.3s;
  }

  .activeAF {
    background-color: #007AFF;
    color: white;
  }
 .activeMF {
    background-color: #4caf50;
    color: white;
  }
}

.language-dropdown-wrapper {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 100;
}

.language-dropdown-link {
  cursor: pointer;
  background-color: #fff;
  color: #333;
  border: 1px solid #dcdfe6;
  border-radius: 20px;
  padding: 6px 15px;
  display: flex;
  align-items: center;
  font-size: 14px;

  .el-icon--right {
    margin-left: 5px;
  }
}

.header::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: -1;
}

// 📱 手机端样式
@media (max-width: 468px) {
  .activeAF {
    background-color: #007AFF;
    color: white;
  }
 .activeMF {
    background-color: #4caf50;
    color: white;
  }
  .header {
    height: 180px;
    padding: 20px;

    .title {
      font-size: 30px;
      margin-top: -5px;
    }

    .date {
      font-size: 16px;
    }

    .shift-selector {
      gap: 8px;
    }

    .shift-option {
      padding: 4px 6px;
      font-size: 12px;
    }

    .language-dropdown-wrapper {
      top: 15px;
      right: 15px;
    }
  }
}

// 📱💻 平板端样式
@media (min-width: 469px) and (max-width: 1024px) {
  .activeAF {
    background-color: #007AFF;
    color: white;
  }
 .activeMF {
    background-color: #4caf50;
    color: white;
  }
  .header {
    height: 190px;

    .title {
      font-size: 36px;
    }

    .date {
      font-size: 17px;
    }

    .shift-selector {
      gap: 12px;
    }

    .shift-option {
      padding: 6px 7px;
      font-size: 14px;
    }

    .language-dropdown-wrapper {
      top: 15px;
      right: 15px;
    }
  }
}

// 💻 电脑端样式
@media (min-width: 1025px) {
  .header {
    height: 190px;

    .title {
      font-size: 45px;
    }

    .date {
      font-size: 18px;
    }

    .shift-selector {
      gap: 15px;
    }

    .shift-option {
      padding: 5px 10px;
      font-size: 16px;
    }

    .language-dropdown-wrapper {
      top: 20px;
      right: 20px;
    }
  }
}

.overview-nav-bar {
  display: flex;
  align-items: center;
  background: #f5f7fa;
  border-radius: 10px 10px 0 0;
  padding: 0 0 0 0;
  margin-bottom: 5px;
  border-bottom: 1.5px solid #f2f3f5;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.02);
  height: 48px;
  user-select: none;
  overflow-x: auto;
  white-space: nowrap;
}

.nav-item {
  display: flex;
  align-items: center;
  font-size: 15px;
  color: #222;
  margin: 0 0 0 0;
  position: relative;
  cursor: pointer;
  height: 100%;
  transition: color 0.2s;
  font-weight: normal;
  white-space: nowrap;
  flex: 1 1 0;
  justify-content: center;
}

.nav-item:last-child {
  margin-right: 0;
}

.nav-item.active {
  color: #197aff;
  font-weight: normal;
}

.nav-item .el-icon {
  font-size: 16px;
  margin-right: 6px;
}

.nav-underline {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: #197aff;
  border-radius: 2px;
  transition: all 0.2s;
}

.overview-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 10px 0;
  background: #f5f7fa;
}

.card-group {
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  padding: 20px 18px 18px 18px;
  margin-bottom: 0;
}

.card-title,
.arrival-title {
  display: flex;
  align-items: center;
  font-size: 16px;
  font-weight: bold;
  color: #333;
  margin-bottom: 18px;
  gap: 0;
}

.card-list {
  display: flex;
  flex-direction: row;
  gap: 18px;
  flex-wrap: wrap;
}

.card-list .card-group {
  flex: 1 1 0;
  min-width: 320px;
  max-width: 100%;
  box-sizing: border-box;
}

.card-item {
  flex: 1 1 120px;
  min-width: 100px;
  background: #f8fafc;
  border-radius: 10px;
  padding: 16px 10px 10px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.03);
}

.card-icon {
  font-size: 32px;
  color: #409EFF;
  margin-bottom: 6px;
}

.card-label {
  font-size: 15px;
  color: #666;
  margin-bottom: 4px;
}

.card-value {
  font-size: 22px;
  font-weight: bold;
  color: #222;
}

.unit {
  font-size: 13px;
  color: #888;
  margin-left: 2px;
}

.chart-placeholder {
  min-height: 80px;
  align-items: center;
  justify-content: center;
  color: #bbb;
  font-size: 15px;
}

.arrival-group {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.08);
  padding: 18px 18px 10px 18px;
  border: 1px solid #f2f3f5;
  margin-top: 0;
}

.arrival-title {
  display: flex;
  align-items: center;
  font-size: 16px;
  font-weight: bold;
  color: #333;
  margin-bottom: 18px;
  gap: 0;
}

.arrival-title-icon {
  color: #b07cff;
  font-size: 20px;
}

.arrival-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: auto;
  position: relative;
}

.arrival-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  width: 100%;
  flex: none;
  padding: 0 2px;
}

.arrival-icon {
  font-size: 44px;
  margin-bottom: 4px;
}

.arrival-icon-orange {
  color: #fa915c;
}

.arrival-icon-blue {
  color: #3b7cff;
}

.arrival-icon-cyan {
  color: #1db6c7;
}

.arrival-label {
  font-size: 12px;
  color: #666;
  margin-bottom: 2px;
}

.arrival-value {
  font-size: 22px;
  font-weight: bold;
  color: #1976f9;
  margin-bottom: 0;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 2px;
}

.arrival-value-orange {
  color: #fa915c;
}

.arrival-value-blue {
  color: #3b7cff;
}

.arrival-value-cyan {
  color: #1db6c7;
}

.arrival-unit {
  font-size: 14px;
  color: #bdbdbd;
  font-weight: 400;
  margin-left: 2px;
}

.process-chart-wrapper {
  width: 100%;
  min-height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.process-chart {
  width: 100%;
  height: 100px;
  min-width: 220px;
}

.eff-chart-wrapper {
  width: 100%;
  min-height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.eff-chart {
  width: 100%;
  height: 100px;
  min-width: 220px;
}

.warning-group {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.08);
  padding: 18px 18px 10px 18px;
  margin-bottom: 10px;
  border: 1.5px solid #f2f3f5;
}

.warning-list {
  width: 100%;
  margin-top: 8px;
}

.warning-row {
  display: flex;
  align-items: center;
  border-bottom: 1px solid #f0f0f0;
  padding: 8px 0;
  font-size: 15px;
  position: relative;
}

.risk-tag {
  display: inline-block;
  min-width: 22px;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 13px;
  color: #fff;
  margin-right: 8px;
  text-align: center;
}

.risk-tag.green {
  background: #4caf50;
}

.risk-tag.red {
  background: #e74c3c;
}

.mat-name {
  flex: 1;
  font-weight: 500;
  color: #222;
}

.mat-num {
  display: inline-block;
  background: #4caf50;
  color: #fff;
  border-radius: 10px;
  font-size: 13px;
  padding: 2px 8px;
  margin-right: 8px;
  min-width: 28px;
  text-align: center;
}

.mat-num.green {
  background: #4caf50;
}

.mat-num.blue {
  background: #409EFF;
}

.expand-btn {
  cursor: pointer;
  margin-left: 8px;
  font-size: 18px;
  color: #bbb;
  transition: color 0.2s;
}

.expand-btn:hover {
  color: #409EFF;
}

.warning-detail {
  background: #f6f8fa;
  border-radius: 6px;
  margin: 0 0 10px 0;
  padding: 10px 16px 10px 32px;
  font-size: 14px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.03);
}

.detail-row {
  display: flex;
  align-items: center;
  margin-bottom: 4px;
}

.detail-label {
  min-width: 120px;
  color: #888;
}

.detail-value {
  font-weight: bold;
  color: #222;
  margin-left: 8px;
}

.detail-value.blue {
  color: #409EFF;
}

.detail-value.red {
  color: #e74c3c;
}

.detail-value.green {
  color: #4caf50;
}

.detail-value {
  &.blue {
    color: #409EFF;
  }

  &.red {
    color: #e74c3c;
  }

  &.green {
    color: #4caf50;
  }
}

.fade-enter-active,
.fade-leave-active {
  transition: all 0.2s;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
  transform: translateY(-8px);
}

@media (max-width: 468px) {
  .overview-cards {
    gap: 10px;
  }

  .card-list {
    flex-direction: column;
    gap: 10px;
    flex-wrap: wrap;
  }

  .card-item {
    min-width: 0;
    width: 100%;
  }

  .arrival-list {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-auto-rows: auto;
    position: relative;
  }

  /* 分割线样式：所有端都显示 */
  .arrival-divider-flex {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 8px auto;
    width: 100%;
    height: 25px;
    box-sizing: border-box;
  }

  .divider-line {
    flex: 1;
    border-bottom: 1px dashed #ccc;
    height: 0;
    margin: 0 8px;
  }

  .divider-img {
    width: 60px;
    height: 40px;
    object-fit: contain;
    display: block;
  }
}

@media (min-width: 469px) {
  .arrival-divider-flex {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 8px auto;
    width: 100%;
    height: 25px;
    box-sizing: border-box;
  }

  .divider-line {
    flex: 1;
    border-bottom: 1px dashed #ccc;
    height: 0;
    margin: 0 8px;
  }

  .divider-img {
    width: 60px;
    height: 40px;
    object-fit: contain;
    display: block;
  }
}

.summary-group {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
  background: none;
  padding: 0 0 10px 0;
}

.summary-item {
  flex: 1;
  text-align: center;
}

.summary-title {
  color: #444;
  font-size: 15px;
  font-weight: 400;
  margin-bottom: 2px;
}

.summary-value {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 2px;
}

.summary-number {
  color: #1976f9;
  font-size: 22px;
  font-weight: bold;
  font-family: inherit;
}

.summary-unit {
  color: #bdbdbd;
  font-size: 14px;
  font-weight: 400;
  margin-left: 2px;
}

@media (max-width: 768px) {
  .summary-group {
    flex-direction: row;
    gap: 0;
  }

  .summary-title {
    font-size: 13px;
  }

  .summary-number {
    font-size: 18px;
  }

  .summary-unit {
    font-size: 12px;
  }
}

.arrival-img {
  width: 50px;
  height: 50px;
  object-fit: contain;
  margin-bottom: 4px;
}

.arrival-title-img {
  width: 16px;
  height: 16px;
  object-fit: contain;
  margin-right: 6px;
  vertical-align: middle;
  margin-top: -1px;
}

.process-title-img {
  width: 16px;
  height: 16px;
  object-fit: contain;
  margin-right: 6px;
  vertical-align: middle;
}

.user-title-img {
  width: 16px;
  height: 16px;
  object-fit: contain;
  margin-right: 6px;
  vertical-align: middle;
}

.warning-title-img {
  width: 16px;
  height: 16px;
  object-fit: contain;
  margin-right: 6px;
  vertical-align: middle;
}

.warning-bar-chart-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}

.warning-bar-label {
  font-size: 14px;
  color: #666;
  font-weight: 500;
}

.warning-bar-container {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 5px;
  background-color: #f0f0f0;
  border-radius: 5px;
  overflow: hidden;
  height: 20px;
}

.warning-bar-bg {
  width: 100%;
  height: 100%;
  background-color: #e0e0e0;
  border-radius: 5px;
  position: relative;
}

.warning-bar-fill {
  height: 100%;
  background-color: #e74c3c;
  border-radius: 5px;
  position: absolute;
  top: 0;
  left: 0;
  transition: width 0.3s ease-in-out;
}

.warning-bar-value {
  font-size: 14px;
  font-weight: bold;
  color: #222;
}

.bar-chart-2rows-wrapper {
  margin-top: 10px;
  padding: 10px 0 0 0;
}

.bar-row {
  display: flex;
  align-items: center;
  margin-bottom: 18px;
}

.bar-label {
  width: 25px;
  text-align: right;
  font-size: 15px;
  color: #888;
  margin-right: 10px;
  flex-shrink: 0;
}

.bar-bg {
  flex: 1;
  height: 22px;
  background: #f0f0f0;
  border-radius: 12px;
  position: relative;
  overflow: hidden;
  margin-right: 10px;
}

.bar-fill {
  height: 100%;
  border-radius: 12px;
  position: absolute;
  left: 0;
  top: 0;
  transition: width 0.3s;
}

.bar-value {
  width: 60px;
  text-align: left;
  font-size: 15px;
  color: #444;
  font-weight: bold;
  margin-left: 5px;
  flex-shrink: 0;
}

.bar-x-axis {
  display: flex;
  justify-content: space-between;
  margin-left: 25px;
  margin-top: -10px;
  font-size: 13px;
  color: #bdbdbd;
  width: calc(100% - 70px - 25px);
}

.bar-tick {
  display: inline-block;
  min-width: 20px;
  text-align: center;
}

/* 新增温湿度卡片样式 */
.env-main {
  display: flex;
  gap: 16px;
  margin-bottom: 10px;
  width: 100%;
}

.env-block {
  flex: 1 1 0;
  min-width: 0;
  background: #f8fafc;
  border-radius: 12px;
  padding: 15px 0;
  text-align: center;
  margin: 0 8px;
}

.env-block1 {
  padding: 20px 0;
}

.env-block:first-child {
  margin-left: 0;
}

.env-block:last-child {
  margin-right: 0;
}

.env-label {
  color: #888;
  font-size: 15px;
  margin-bottom: 2px;
  position: relative;
}

.tag {
  position: absolute;
  left: 0;
  top: -15px;
}

.env-value {
  color: #197aff;
  font-size: 22px;
  font-weight: bold;
  margin-bottom: 2px;
}

.env-value small {
  font-size: 12px;
  color: #888;
}

.env-range {
  color: #bbb;
  font-size: 11px;
}

.env-proc {
  font-size: 20px;
  color: #222;
  font-weight: 500;
  margin-bottom: 2px;
}

.af-tag {
  width: auto;
  height: auto;
  padding: 2px 5px;
  border-radius: 5px;
  background-color: #4caf50;
  color: white;
}

.mf-tag {
  background-color: #197aff;
}

.container-box {
  width: 100%;
  max-width: 650px;
  margin: 0 auto;
}

@media (max-width: 468px) {
  .container-box {
    max-width: 100vw;
    margin: 0;
  }
}

/* 手机端分割线样式 */
@media (max-width: 468px) {
  .stock-summary .border {
    width: 100%;
    height: 2px;
    background: #e74c3c;
    margin: 10px 0;
    border-radius: 1px;
    display: block;
  }
}

/* 非手机端隐藏分割线 */
@media (min-width: 469px) {
  .stock-summary .border {
    display: none;
  }
}
</style>
